package com.ssy.invoicing.common.util;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;
import org.springframework.stereotype.Component;

/**
 * Json日期格式化帮助类
 * Comment of JsonDateSerializer
 * @author suoyao.shen
 */
@Component
public class JsonDateSerializer extends JsonSerializer<Date> {
    
    private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

    /* (non-Javadoc)
     * @see org.codehaus.jackson.map.JsonSerializer#serialize(java.lang.Object, org.codehaus.jackson.JsonGenerator, org.codehaus.jackson.map.SerializerProvider)
     */
    @Override
    public void serialize(Date date, JsonGenerator gen, SerializerProvider provider)
            throws IOException, JsonProcessingException {
        String formatDate = format.format(date);
        gen.writeString(formatDate);
    }

}
